package com.dinner.struts.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dinner.model.MenuType;
import com.dinner.model.Seller;
import com.dinner.service.MenuTypeService;

public class MenuTypePageAction extends Action {

	private MenuTypeService service = null;

	/**
	 * @return the service
	 */
	public MenuTypeService getService() {
		return service;
	}

	/**
	 * @param service
	 *            the service to set
	 */
	public void setService(MenuTypeService service) {
		this.service = service;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.apache.struts.action.Action#execute(org.apache.struts.action.
	 * ActionMapping, org.apache.struts.action.ActionForm,
	 * javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		String sellerID = request.getParameter("sellerID");
		List<MenuType> list = service.getMenuTypesBySeller(sellerID);
		request.getSession().setAttribute("MenuTypeList", list);

		Seller seller = com.dinner.util.EntityListUtils.getSellerFromList(
				(List<Seller>) request.getSession().getAttribute("SellerList"), sellerID);
		request.setAttribute("Seller", seller);
		return mapping.getInputForward();
	}

}
